<?php 
/*
**模型：回复内容
**inc/class.cates.php
**By QINIAO
*/

	class qiComment{
	var $db;
	function qiComment($dbhandle)
	{
	$this->db = $dbhandle;
	}

	//获取评论
	function getComments($tid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."comments where tid='$tid' order by cTime desc");
	$comms = array();
	while($row = $this->db->fetch_array($res))
	{
	   $comms[] = $row;
	}
	return $comms;
	}
	
	//获取所有评论后台
	function getAllComms($page = 1, $prePageNum)
	{
	$start_limit = !empty($page) ? ($page - 1) * $prePageNum : 0;
	$limit = $prePageNum ? "LIMIT $start_limit, $prePageNum" : '';
	$res = $this->db->query("select * from ".DB_PREFIX."comments order by cTime desc $limit");
	$comms = array();
	while($row = $this->db->fetch_array($res))
	{
	$comms[] = $row;
	}
	return $comms;
	}
	//获取评论数
	function getCommNum($virtue, $setvirtue)
	{
	$where = 'where '.$virtue.'='.$setvirtue.'';
	$res = $this->db->query("SELECT * FROM ".DB_PREFIX."comments $where" );
	$CommNum = $this->db->num_rows($res);
	return $CommNum;
	}

	//添加评论
	function addComment($tid, $uid, $commContent, $ctime)
	{
	$sql = "insert into ".DB_PREFIX."comments (tid, uid, content,cTime) values ('$tid', '$uid', '$commContent', '$ctime')";
	$this->db->query($sql);
	}
	
	//获取一条评论内容，指定评论id
	function getOneComm($commid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."comments where id=$commid");
	$row = $this->db->fetch_array($res);
	if($row)
	{
	$commDate = array(
	'id' => $row['id'],
	'tid' => $row['tid'],
	'uid' => $row['uid'],
	'content' => $row['content'],
	'cTime' => $row['cTime']
	);
	return $commDate;
	}
	}
	
	//更新评论内容
	function updateComm($commDate,$commid)
	{
	$Item = array();
	foreach ($commDate as $key => $data)
	{
		$Item[] = "$key='$data'";
	}
	$upStr = implode(',', $Item);
	$this->db->query("update ".DB_PREFIX."comments set $upStr where id=$commid");
	}
	
	//删除评论
	function deleteComm($commid)
	{
	$this->db->query("delete from ".DB_PREFIX."comments where id=$commid");
	}
	
	}

?>